package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortPoint {
    public static void main(String[] args) {
        List<Point> list=new ArrayList<>();
        list.add(new Point(5,8));
        list.add(new Point(15,60));
        list.add(new Point(1,4));
        list.add(new Point(10,8));
        list.add(new Point(22,35));
        System.out.println("list原始数据:"+list);//list原始数据:[(5,8), (15,60), (1,4), (10,8), (22,35)]

        //自定义排序规则:
        Collections.sort(list, (o1,o2) ->{
                int len1=o1.getX()* o1.getX()+o1.getY()*o1.getY();
                int len2=o2.getX()*o2.getX()+o2.getY()*o2.getY();
                //return len1-len2;
                return len2-len1;

                //return o1.getX()-o2.getX();//按照x坐标升序排列
                //return o2.getY()-o1.getY();//按照y坐标降序排列
            });
        System.out.println(list);//[(15,60), (22,35), (10,8), (5,8), (1,4)]
        list.sort((o1, o2) -> o1.getX()-o2.getX());
        System.out.println(list);//[(1,4), (5,8), (10,8), (15,60), (22,35)]
    }



}
